import createRouteMap from './createRouteMap';
import {createRoute} from './history/baseHistory';
export default function createMatcher(routes){
    //routes 是用户自己配置的 但是用起来不方便
    //pathList会把所有的路由组成一个数组['/','/about','/about/a']
    //pathMap {/:{}}
    let {pathList,pathMap} = createRouteMap(routes);

    function match(){//等会通过用户输入的路径 获取对应的匹配记录
        let record = pathMap[location];//获取对应的记录
        return createRoute(record,{
            path:location
        })
    }

    function addRoutes(routes){//routes动态添加的路由
        createRouteMap(routes,pathList,pathMap)
    }

    return {
        match,
        addRoutes
    }
}